package org.luxor.common.netty.protocol.message;


import org.luxor.common.netty.constant.NettyReasonCode;
import org.luxor.common.netty.protocol.NettyFixedHeader;
import org.luxor.common.netty.protocol.NettyMessageType;
import org.luxor.common.netty.protocol.NettyQoS;
import org.luxor.common.netty.protocol.NettyReasonCodeVariableHeader;
import org.luxor.commons.core.web.IRestStatus;

/**
 * Netty Disconnect Message
 *
 * @author Mr.yan @date 2024/1/31
 */
public class NettyDisconnectMessage extends NettyMessage {

    public NettyDisconnectMessage(NettyFixedHeader fixedHeader, Object variableHeader) {
        super(fixedHeader, variableHeader, null);
    }

    @Override
    public NettyReasonCodeVariableHeader variableHeader() {
        return (NettyReasonCodeVariableHeader) super.variableHeader();
    }

    public static NettyDisconnectMessage from() {
        return from(NettyReasonCode.DISCONNECT);
    }

    public static NettyDisconnectMessage from(IRestStatus restStatus) {
        NettyFixedHeader fixedHeader = new NettyFixedHeader(NettyMessageType.DISCONNECT, false, NettyQoS.AT_MOST_ONCE);
        NettyReasonCodeVariableHeader variableHeader = NettyReasonCodeVariableHeader.from(restStatus);
        return new NettyDisconnectMessage(fixedHeader, variableHeader);
    }
}
